﻿// CBrowserDlg.cpp: 实现文件
//

#include "pch.h"
#include "MFCCef.h"
#include "afxdialogex.h"
#include "CBrowserDlg.h"

#include <include/internal/cef_win.h>
#include <include/internal/cef_ptr.h>
#include <include/cef_browser.h>
#include <include/cef_app.h>

#include "include/views/cef_browser_view.h"
#include "CCefBrowserEventHandler.h"
#include <string>
// CBrowserDlg 对话框

IMPLEMENT_DYNAMIC(CBrowserDlg, CDialogEx)

CBrowserDlg::CBrowserDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_BROSWER_DIG, pParent)
{
	//CefRefPtr<CefCommandLine> command_line = CefCommandLine::GetGlobalCommandLine();
	//CefRefPtr<CefCommandLine> command_line = CefCommandLine::GetGlobalCommandLine();
	
}

CBrowserDlg::~CBrowserDlg()
{
}

void CBrowserDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CBrowserDlg, CDialogEx)
END_MESSAGE_MAP()


// CBrowserDlg 消息处理程序


BOOL CBrowserDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
		//## cef ##

	//没啥用抄来的
	const bool use_views = true;

	//chrome控件信息类
	CefWindowInfo cefWindowInfo;

	CRect crect;
	GetClientRect(crect);
	cefWindowInfo.SetAsChild(GetSafeHwnd(), crect);

	CefBrowserSettings browser_settings;
	// CMFCCefDlg 对话框
	CefRefPtr<CCefBrowserEventHandler> cef_handler = new CCefBrowserEventHandler(use_views);
	cef_handler->m_uname = m_user_name;
	cef_handler->m_pwd = m_password;
	//CefRefPtr<CefCommandLine> command_line = CefCommandLine::GetGlobalCommandLine();
	//std::string url = command_line->GetSwitchValue("url");

	CefString url = param;
	//CefBrowserHost::CreateBrowser(cefWindowInfo, cef_handler, "http://play.2144.cn/rxfs/index.html?id=55721&sid=20", browser_settings, nullptr, nullptr);
	CefBrowserHost::CreateBrowser(cefWindowInfo, cef_handler, url, browser_settings, nullptr, nullptr);
	//## cef ##
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}
